package cn.supermaster.management.web.rest.system;

import cn.supermaster.management.common.annotation.Log;
import cn.supermaster.management.common.domain.SystemMenu;
import cn.supermaster.management.common.domain.SystemRole;
import cn.supermaster.management.common.entity.Ztree;
import cn.supermaster.management.common.enums.BusinessType;
import cn.supermaster.management.common.response.WebResponse;
import cn.supermaster.management.web.service.system.ISMenuService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * All rights Reserved, Designed By www.super-bytecode.com
 *
 * @ProjectName: supermaster-management
 * @Package: cn.supermaster.management.web.rest.system
 * @ClassName: SystemMenuRestController
 * @Description: [菜单信息]
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2021/1/12 0:34
 * @Version: V1.0
 * @Copyright: 2021 www.super-bytecode.comn Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@RestController
@RequestMapping("/system/menu")
public class SystemMenuRestController {
    @Autowired
    private ISMenuService menuService;

    @RequiresPermissions("system:menu:list")
    @PostMapping("/list")
    public List<SystemMenu> queryMenuListByCondition(SystemMenu menu) {
        return menuService.queryMenuListByCondition(menu);
    }

    /**
     * 删除菜单
     */
    @Log(title = "菜单管理", businessType = BusinessType.DELETE)
    @RequiresPermissions("system:menu:remove")
    @GetMapping("/remove/{menuId}")
    public WebResponse doRemoveMenuInformation(@PathVariable("menuId") Long menuId) {
        return menuService.doRemoveMenuInformation(menuId);
    }

    /**
     * 新增保存菜单
     */
    @Log(title = "菜单管理", businessType = BusinessType.INSERT)
    @RequiresPermissions("system:menu:add")
    @PostMapping("/add")
    public WebResponse doAddMenuInformation(@Validated SystemMenu menu) {
        return menuService.doAddMenuInformation(menu);
    }


    /**
     * 修改保存菜单
     */
    @Log(title = "菜单管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("system:menu:edit")
    @PostMapping("/edit")
    public WebResponse doMofifyMenuInformation(@Validated SystemMenu menu) {
        return menuService.doMofifyMenuInformation(menu);
    }

    /**
     * 校验菜单名称
     */
    @PostMapping("/checkMenuNameUnique")
    public String doCheckMenuNameUnique(SystemMenu menu) {
        return menuService.doCheckMenuNameUnique(menu);
    }

    /**
     * 加载角色菜单列表树
     */
    @GetMapping("/roleMenuTreeData")
    public List<Ztree> loadRoleMenuTreeInformation(SystemRole role) {
        return menuService.loadRoleMenuTreeInformation(role);
    }

    /**
     * 加载所有菜单列表树
     */
    @GetMapping("/menuTreeData")
    public List<Ztree> menuTreeData() {
        return menuService.loadAllMenuTreeInformation();
    }
}